import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import movenment.Skeleton;


public class Menu {
	// static fields:
    private static final String VERSION = "Version 2.0";
    private Skeleton spel;
	private JFrame frame;
	
	public static void main(String args[]){
		new Menu();
	}
	
	public Menu(){
		makeFrame();
	}
	/**
     * Create the Swing frame and its content.
     */
    private void makeFrame()
    {
        frame = new JFrame("Snake");  
        JPanel contentPane = (JPanel)frame.getContentPane();
        contentPane.setSize(640, 480);
        makeMenuBar(frame);
        
     // Specify the layout manager with nice spacing
        contentPane.setLayout(new BorderLayout(6, 6));
        JLabel filenameLabel = new JLabel();
        contentPane.add(filenameLabel, BorderLayout.NORTH);

        JLabel statusLabel = new JLabel(VERSION);
        contentPane.add(statusLabel, BorderLayout.SOUTH);
        
        final JLabel menuThings = new JLabel();
        contentPane.add(menuThings, BorderLayout.CENTER);
        
        menuThings.setLayout(new BoxLayout(menuThings, BoxLayout.PAGE_AXIS));
        
        JLabel secondMenu = new JLabel();
        menuThings.add(secondMenu);
        ActionListener playAction = new ActionListener() {
            public void actionPerformed(ActionEvent e) { play(); }
        };
        createAButton("Play", menuThings, playAction);
        //addAButton("Help", menuThings);
        //addAButton("Credits", menuThings);
        

        
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setSize(640, 480);
        
        // center the frame on screen
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation(d.width/2 - frame.getWidth()/2, d.height/2 - frame.getHeight()/2);
        frame.setVisible(true);   
    }
    
    
    private static void createAButton(String text, Container container, ActionListener action) {
        JButton button = new JButton(text);
        button.setSize(100, 25);
        button.setMaximumSize(new Dimension(100, 30));
        button.setMinimumSize(new Dimension(100, 30));
        button.setPreferredSize(new Dimension(100, 30));
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        button.addActionListener(action);
        container.add(button);
    }
    private void play(){
    	//frame.setVisible(false);
    	spel = new Skeleton();
    	frame.add(spel);
    }
    public void close(){
    	frame.setVisible(true);
    	//spel.dispose();
    }
    private void makeMenuBar(JFrame frame){
    	final int SHORTCUT_MASK =
    			Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    	JMenuBar menubar = new JMenuBar();
        frame.setJMenuBar(menubar);
        
        JMenu menu;
        JMenuItem item;
     // create the File menu
        menu = new JMenu("File");
        menubar.add(menu);

        //menu.addSeparator();

        item = new JMenuItem("Quit");
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, SHORTCUT_MASK));
        item.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) { quit(); }
        });
        menu.add(item);




    // create the Help menu
    menu = new JMenu("Help");
    menubar.add(menu);
    
    item = new JMenuItem("About Snake...");
        item.addActionListener(new ActionListener() {
                           public void actionPerformed(ActionEvent e) { showAbout(); }
                       });
    menu.add(item);
    }
    /**
     * Shows information about the program.
     */
    private void showAbout()
    {
        JOptionPane.showMessageDialog(frame, 
                    "Snake\n" + VERSION,
                    "About Snake", 
                    JOptionPane.INFORMATION_MESSAGE);
    }
    
    /**
     * Quit function: quit the application.
     */
    private void quit()
    {
        System.exit(0);
    }
}
